﻿using DataStructure;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace DataStructure.Test
{


    /// <summary>
    ///This is a test class for MyHeapTest and is intended
    ///to contain all MyHeapTest Unit Tests
    ///</summary>
    [TestClass()]
    public class MyHeapTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        [TestMethod()]
        public void MyHeapCtorTest()
        {
            const int SIZE = 9;
            
            Random RandomClass = new Random();
            int[] radmonarr = new int[SIZE];
            for (int i = 0; i < SIZE; i++)
            {
                int rn = RandomClass.Next(1, 100);
                radmonarr[i] = rn;
                Console.Write(rn + " ");
            }
            Console.WriteLine();

            MyHeap aHeap = new MyHeap(radmonarr);
            aHeap.ShowArray();
        }

        /// <summary>
        ///A test for Remove
        ///</summary>
        [TestMethod()]
        public void RemoveTest()
        {
            MyHeap heap = new MyHeap();
            heap.HeapArray = new int[] {
              //  13, 38,27, 49, 76, 65, 49, 97
              82, 77, 78, 71, 31, 58, 2, 54, 21
            };
            heap.CurrSize = heap.HeapArray.Length;
            heap.ShowArray();
            int root = heap.Remove();
            Console.WriteLine();
            Console.WriteLine(root);
            heap.ShowArray();
        }
        public void SortedTest()
        {

            const int SIZE = 9;
            MyHeap aHeap = new MyHeap(SIZE);
            Random RandomClass = new Random();
            int [] radmonarr = new int[SIZE];
            for (int i = 0; i < SIZE; i++)
            {
                int rn = RandomClass.Next(1, 100);
                
                aHeap.Insert(rn);
                aHeap.IncSize();
            }

            Console.Write("Random: ");
            aHeap.ShowArray();

            Console.WriteLine();
            Console.Write("Heap: ");
            for (int i = (int)SIZE / 2 - 1; i >= 0; i--)
                aHeap.ShiftDown(i);
            aHeap.ShowArray();

            for (int i = SIZE - 1; i >= 0; i--)
            {
                int bigNode = aHeap.Remove();
                aHeap.Insert(bigNode);
            }
            Console.WriteLine();
            Console.Write("Sorted: ");
            aHeap.ShowArray();
        }

        /// <summary>
        ///A test for Insert
        ///</summary>
        [TestMethod()]
        public void InsertTest()
        {
            MyHeap heap = new MyHeap();
            heap.HeapArray = new int[] {
              //  13, 38,27, 49, 76, 65, 49, 97
              82, 77, 78, 71, 31, 58, 2, 54, 21
            };
            heap.CurrSize = heap.HeapArray.Length;
            Console.WriteLine();
            Console.WriteLine("orignial heap:");
            heap.ShowArray();

            int root = heap.Remove();
            Console.WriteLine();
            Console.WriteLine("after remove root: {0}", root);
            heap.ShowArray();

            heap.Insert(root);
            Console.WriteLine();
            Console.WriteLine("after add root: {0}", root);
            heap.ShowArray();

        }

        /// <summary>
        ///A test for MyHeap Constructor
        ///</summary>
        [TestMethod()]
        public void MyHeapConstructorTest()
        {
            var arr = new int[] {
              //  13, 38,27, 49, 76, 65, 49, 97
              82, 78, 71,  58, 2, 54, 21,77,31
            };
            MyHeap heap = new MyHeap(arr);
            heap.CurrSize = heap.HeapArray.Length;
            Console.WriteLine();
            Console.WriteLine("orignial heap:");
            heap.ShowArray();

        }

        /// <summary>
        ///A test for HeapSort
        ///</summary>
        [TestMethod()]
        public void HeapSortTest()
        {
            var arr = new int[] {
              //  13, 38,27, 49, 76, 65, 49, 97
              82, 78, 71,  58, 2, 54, 21,77,31
            };
            MyHeap heap = new MyHeap(arr);
            heap.CurrSize = heap.HeapArray.Length;
            Console.WriteLine();
            Console.WriteLine("orignial heap:");
            heap.ShowArray();

            Console.WriteLine();
            Console.WriteLine("after sort:");
            heap.HeapSort();
            heap.ShowArray();
        }

        /// <summary>
        ///A test for HeapSort
        ///</summary>
        [TestMethod()]
        [DeploymentItem("DataStructureInCs.dll")]
        public void HeapSortTest1()
        {
            MyHeap_Accessor target = new MyHeap_Accessor(); // TODO: Initialize to an appropriate value
            int[] A = null; // TODO: Initialize to an appropriate value
            int HeapSize = 0; // TODO: Initialize to an appropriate value
            target.HeapSort(A, HeapSize);
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }
    }
}
